import { createConnection } from "./dbutils.js";

const PIE_DATA_1 = "SELECT \
Type , \
Total \
FROM \
cloud_computing_demo.alarm;";

function queryPieData(success) {
    let connection = createConnection();
    connection.connect();
    connection.query(PIE_DATA_1, (err, res) => {
        if (err == null) {
            console.log(res);
            success(res);
        } else {
            throw new Error(err);
        }
    });
    connection.end();
}

const PIE_DATA_2 = "SELECT \
Level , \
Total \
FROM \
cloud_computing_demo.alarm;";


function queryPieData2(success) {
    let connection = createConnection();
    connection.connect();
    connection.query(PIE_DATA_2, (err, res) => {
        if (err == null) {
            console.log(res);
            success(res);
        } else {
            throw new Error(err);
        }
    });
    connection.end();
}


const JOB_LIST = "SELECT \
device_name , \
precinct_name \
FROM \
cloud_computing_demo.device_config LIMIT 100";


function queryJobList(success) {
    let connection = createConnection();
    connection.connect();
    connection.query(JOB_LIST, (err, res) => {
        if (err == null) {
            console.log(res);
            success(res);
        } else {
            throw new Error(err);
        }
    });
    connection.end();
}

export { queryPieData, queryPieData2, queryJobList };
